From 71ab7fcbe402262d9a9be0bd396b2229e4eeff56 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Tue, 9 Aug 2005 20:24:23 +0000 Subject: [PATCH] added BablImage --- ChangeLog | 12 +++ babl/Makefile.am | 3 + babl/babl-classes.h | 45 ++++------- babl/babl-component.c | 1 + babl/babl-conversion.c | 6 +- babl/babl-image.c | 178 +++++++++++++++++++++++++++++++++++++++++ babl/babl-image.h | 32 ++++++++ babl/babl-model.c | 1 + 8 files changed, 245 insertions(+), 33 deletions(-) create mode 100644 babl/babl-image.c create mode 100644 babl/babl-image.h diff --git a/ChangeLog b/ChangeLog index 413251c..ac44b0e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-08-09 Øyvind Kolås + + * babl/Makefile.am + * babl/babl-image.c + * babl/babl-image.h + * babl/babl-classes.h: Added BablImage class. + + * babl/babl-component.c + * babl/babl-conversion.c + * babl/babl-model.c: Handle BABL_IMAGE in switches. + + 2005-08-09 Øyvind Kolås * .cvsignore: added INSTALL and README. diff --git a/babl/Makefile.am b/babl/Makefile.am index 9337725..2359147 100644 --- a/babl/Makefile.am +++ b/babl/Makefile.am @@ -8,6 +8,7 @@ c_sources = \ babl-component.c \ babl-conversion.c \ babl-fish.c \ + babl-image.c \ babl-introspect.c \ babl-memory.c \ babl-model.c \ @@ -25,6 +26,7 @@ h_sources = \ babl-ids.h \ babl-internal.h \ babl-introspect.h \ + babl-image.h \ babl-fish.h \ babl-memory.h \ babl-model.h \ @@ -42,6 +44,7 @@ library_include_HEADERS = \ babl-component.h \ babl-conversion.h \ babl-fish.h \ + babl-image.h \ babl-model.h \ babl-pixel-format.h \ babl-sampling.h \ diff --git a/babl/babl-classes.h b/babl/babl-classes.h index 29f9ed3..7adaa88 100644 --- a/babl/babl-classes.h +++ b/babl/babl-classes.h @@ -20,33 +20,6 @@ #ifndef _BABL_CLASSES_H #define _BABL_CLASSES_H -#ifdef BABL_SKETCHPAD - -BablClassType - BablInstance - BablType - BablSampling - BablComponent - BablModel - BablPixelFormat - BablConversion - BablConversionType - BablConversionTypePlanar - BablConversionModelPlanar - BablConversionPixelFormat - BablConversionPixelFormatPlanar - -maybe it could make sense to split model into the following, where -the current model would live on in the component model,. - BablModelType - BablModelSampling - BablModelComponent - - BablConversionModelType - BablConversionModelSampling - BablConversionModelComponent -#endif - /* Type and PixelFormat */ typedef void (*BablFuncLinear) (void *src, void *dst, @@ -89,6 +62,7 @@ typedef enum { BABL_CONVERSION_PIXEL_FORMAT_PLANAR, BABL_FISH, + BABL_IMAGE, BABL_SKY } BablClassType; @@ -199,9 +173,19 @@ typedef struct typedef struct { - BablInstance instance; - union Babl *source; - union Babl *destination; + BablInstance instance; + int bands; + BablComponent **component; + void **data; + int *pitch; + int *stride; +} BablImage; + +typedef struct +{ + BablInstance instance; + union Babl *source; + union Babl *destination; } BablFish; typedef union @@ -215,6 +199,7 @@ typedef union BablPixelFormat pixel_format; BablConversion conversion; BablFish fish; + BablImage image; } Babl; diff --git a/babl/babl-component.c b/babl/babl-component.c index ea1e361..f4180e2 100644 --- a/babl/babl-component.c +++ b/babl/babl-component.c @@ -95,6 +95,7 @@ babl_component_new (const char *name, case BABL_CONVERSION_PIXEL_FORMAT: case BABL_CONVERSION_PIXEL_FORMAT_PLANAR: case BABL_FISH: + case BABL_IMAGE: babl_log ("%s(): %s unexpected", __FUNCTION__, babl_class_name (babl->instance.type)); break; diff --git a/babl/babl-conversion.c b/babl/babl-conversion.c index 8cddb12..a42cc2d 100644 --- a/babl/babl-conversion.c +++ b/babl/babl-conversion.c @@ -129,9 +129,6 @@ conversion_new (const char *name, self->time_cost = time_cost; self->loss = loss; - assert (BABL_IS_BABL (self->source)); - assert (BABL_IS_BABL (self->destination)); - babl_add_ptr_to_list ((void ***)&(source->type.from), self); babl_add_ptr_to_list ((void ***)&(destination->type.to), self); @@ -226,6 +223,9 @@ babl_conversion_new (const char *name, va_end (varg); + assert (source); + assert (destination); + self = conversion_new (name, id, source, destination, time_cost, loss, linear, planar, planar_bit); diff --git a/babl/babl-image.c b/babl/babl-image.c new file mode 100644 index 0000000..3edc962 --- /dev/null +++ b/babl/babl-image.c @@ -0,0 +1,178 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include + +#include "babl-internal.h" +#include "babl-image.h" +#include "babl-type.h" +#include "babl-component.h" + +#define BABL_MAX_BANDS 32 + +static BablImage *db[100]={NULL,}; + +#if 0 +static int +each_babl_image_destroy (Babl *babl, + void *data) +{ + babl_free (babl->image.component); + babl_free (babl->image.pitch); + babl_free (babl->image.stride); + babl_free (babl); + + return 0; /* continue iterating */ +} +#endif + +static BablImage * +image_new (int bands, + BablComponent **component, + void **data, + int *pitch, + int *stride) +{ + BablImage *self; + int band; + + self = babl_calloc (sizeof (BablImage), 1); + + self->instance.type = BABL_IMAGE; + self->instance.id = 0; + self->instance.name = "babl image"; + + self->bands = bands; + + self->component = babl_malloc (sizeof (BablComponent*) * (bands+1)); + self->data = babl_malloc (sizeof (void*) * (bands+1)); + self->pitch = babl_malloc (sizeof (int) * (bands+1)); + self->stride = babl_malloc (sizeof (int) * (bands+1)); + + for (band=0; band < bands; band++) + { + self->component[band] = component[band]; + self->data[band] = data[band]; + self->pitch[band] = pitch[band]; + self->stride[band] = stride[band]; + } + self->component[band] = NULL; + self->data[band] = NULL; + self->pitch[band] = 0; + self->stride[band] = 0; + + return self; +} + +BablImage * +babl_image_new (void *first, + ...) +{ + va_list varg; + BablImage *self; + int bands = 0; + BablComponent *component [BABL_MAX_BANDS]; + void *data [BABL_MAX_BANDS]; + int pitch [BABL_MAX_BANDS]; + int stride [BABL_MAX_BANDS]; + + const char *arg = first; + + va_start (varg, first); + + while (1) + { + BablComponent *new_component = NULL; + if (!arg) + break; + + if (BABL_IS_BABL (arg)) + { + Babl *babl = (Babl*)arg; + + if (babl->instance.type == BABL_COMPONENT) + { + new_component = (BablComponent *)babl; + } + else + { + babl_log ("%s(): %s unexpected", + __FUNCTION__, babl_class_name (babl->instance.type)); + return NULL; + } + } + else + { + new_component = babl_component (arg); + } + + component [bands] = new_component; + data [bands] = va_arg (varg, void*); + pitch [bands] = va_arg (varg, int); + stride [bands] = va_arg (varg, int); + bands++; + + if (bands>=BABL_MAX_BANDS) + { + babl_log ("%s(): maximum number of bands (%i) exceeded for BablImage", + __FUNCTION__, BABL_MAX_BANDS); + } + + arg = va_arg (varg, char *); + } + + va_end (varg); + + + self = image_new (bands, component, data, pitch, stride); + + return self; +} + +void +babl_image_each (BablEachFunction each_fun, + void *user_data) +{ + int i; + return; + + while (db[i]) + { + if (each_fun ((Babl *) (db[i]), user_data)) + { + return; + } + else + { + i++; + } + } +} + + +void +babl_image_destroy (void) +{ +} + +void +babl_image_init (void) +{ +} diff --git a/babl/babl-image.h b/babl/babl-image.h new file mode 100644 index 0000000..db4a0c5 --- /dev/null +++ b/babl/babl-image.h @@ -0,0 +1,32 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _BABL_IMAGE_H +#define _BABL_IMAGE_H + +#include "babl-classes.h" + +void babl_image_init (void); +void babl_image_introspect (void); +void babl_image_each (BablEachFunction each_fun, + void *user_data); +void babl_image_destroy (void); +BablImage * babl_image_new (void *first_component, + ...); +#endif diff --git a/babl/babl-model.c b/babl/babl-model.c index c0acc39..e1657ae 100644 --- a/babl/babl-model.c +++ b/babl/babl-model.c @@ -119,6 +119,7 @@ babl_model_new (const char *name, case BABL_CONVERSION_PIXEL_FORMAT: case BABL_CONVERSION_PIXEL_FORMAT_PLANAR: case BABL_FISH: + case BABL_IMAGE: babl_log ("%s(): %s unexpected", __FUNCTION__, babl_class_name (babl->instance.type)); break; -- 2.30.2